//
//  MyCarItemView.m
//  SecondPage
//
//  Created by xiong qi on 13-5-6.
//  Copyright (c) 2013年 winston. All rights reserved.
//

#import "MyCarItemView.h"

@implementation MyCarItemView
@synthesize dataSource;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        UIImage *img=[UIImage imageNamed:@"AllAuto_Comparison_Image_BG"];
        img=[img stretchableImageWithLeftCapWidth:15 topCapHeight:12];
        self.image = img;
        
        //因为背景图有2个像素的阴影
        int width = frame.size.width-6;
        int height = width*0.75;
        imageView = [[UIImageView alloc]initWithFrame:CGRectMake(3,1,width,height)];
        [self addSubview:imageView];
        [imageView release];
        imageView.clipsToBounds = YES;
        imageView.contentMode = UIViewContentModeScaleAspectFill;

        titlebackground = [[UIView alloc] initWithFrame:CGRectMake(3, frame.size.height-25, width, 20)];
        [titlebackground setBackgroundColor:[UIColor colorWithRed:0.29 green:0.29 blue:0.29 alpha:1.0]];
        [self addSubview:titlebackground];
        [titlebackground release];
        

        titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 0, titlebackground.frame.size.width-10, titlebackground.frame.size.height)];
        titleLabel.textColor = [UIColor whiteColor];
        titleLabel.textAlignment = NSTextAlignmentLeft;
        titleLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:12];
        [titleLabel setBackgroundColor:[UIColor clearColor]];
        [titlebackground addSubview:titleLabel];
        [titleLabel release];
    }
    return self;
}

-(void)RefreshImageData:(FavoriteModuleView *)moduleview
{
    self.dataSource = moduleview.selectData;
    if (dataSource) {
        [self SetData];
    }
    
}

-(void)SetData
{
    NSString * rootpath = [dataSource objectForKey:Favorite_Root];
    NSString * imagepath = [NSString stringWithFormat:@"%@/%@",rootpath,[dataSource objectForKey:Favorite_Image_Middle]];
    UIImage * image = [[UIImage alloc] initWithContentsOfFile:imagepath];
    if (image) {
        imageView.image = image;
        [image release];
    }
    
    
    titleLabel.text = [dataSource objectForKey:Favorite_Title];
}

-(NSString *)GetCode
{
    return [self.dataSource objectForKey:CarInfo_ColorCode];
}

-(void)dealloc
{
    self.dataSource = nil;
    [super dealloc];
}

@end
